layui.use(['form','layer','upload'],function(){
    var form = layui.form
        ,layer = parent.layer === undefined ? layui.layer : top.layer,
        upload =layui.upload,
        $ = layui.jquery;
	
	
	 //普通图片上传
	 //先定义一个变量，用来存储回传的图片地址
	 /*var img_url = "";
	  var uploadInst = upload.render({
	    elem: '#test1'
	    ,url: 'http://127.0.0.1:88/index.php/renwu/renwu/renwuImg' //改成您自己的上传接口
	    ,before: function(obj){
	      //预读本地文件示例，不支持ie8
	      $("#shili").hide();
	      obj.preview(function(index, file, result){
	        $('#demo1').attr('src', result); //图片链接（base64）
	      });
	    }
	    ,done: function(res){
	      //如果上传失败
	      if(res.code == 200){
	        img_url = res.url;
	        $("#renwu_img_url").val(img_url);
	        //console.log(img_url);
	      }else{
	      	return layer.msg('店铺截图上传失败');
	      }
	      //上传成功
	    }
	    ,error: function(){
	      //演示失败状态，并实现重传
	      var demoText = $('#demoText');
	      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	      demoText.find('.demo-reload').on('click', function(){
	        uploadInst.upload();
	      });
	    }
	  });*/
	
    form.on("submit(addrenwu)",function(data){
        //弹出loading
        //alert($("#file").val());
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        var action 	= data.form.action;//表单提交URL地址
        //var da		= data.field;
        layer.msg(data.field);
        $.post("http://127.0.0.1:88/index.php/renwu/renwu/addRenwu",data.field,function(obj){
        	
        });
        // 实际使用时的提交信息
        /*$.post(action,{
         	"renwu_name"			: $(".renwu_name").val,
         	"renwu_wangwang"		: $(".renwu_wangwang").val,
         	"renwu_type"			: $(".renwu_type").val,
         	"user_name"			: localStorage.login_name,
         	"renwu_img_url"		: img_url
        },function(res){
        	
        })*/
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("商铺添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        //return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})